<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>sso登录</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/js/bootstrap.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery.form/4.3.0/jquery.form.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery-validate/1.19.3/jquery.validate.js"></script>
</head>
<body>
<div class="container">
    <form class="loginForm" role="form" method="post" action="/pf-auth/login">
        <h2 class="form-signin-heading">用户登录</h2>
        <div class="mb-3">
            <label for="username" class="form-label">用户名</label>
            <input type="text" class="form-control" id="username" name="username" placeholder="请输入用户名/手机号" required>
        </div>
        <div class="mb-3">
            <label for="password" class="form-label">密码</label>
            <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码" required>
        </div>
        <p>
            <!--TODO 登录方式不晓得怎么传过去，form提交方式不能加到请求头，ajax重定向还有问题-->
            <label for="loginType" class="form-label">登录方式</label>
            <select id="loginType" name="loginType" class="form-select">
                <option value="1" selected>用户名</option>
                <option value="0">手机号</option>
            </select>
        </p>
        <button class="btn btn-lg btn-primary btn-block" id="loginBtn" type="submit">登录</button>
    </form>
</div>
</body>
<script type="application/javascript">
    /*(function () {
        $("#loginBtn").click(function () {
            var data = {
                username: $("#username").val(),
                password: $("#password").val(),
                loginType: $("#loginType").val(),
            };
            for (let key in data) {
                if(!data[key]){
                    alert("请完善登录信息！");
                    return false;
                }
            }
            $.ajax({
                type: "POST",
                url: "/pf-auth/login",
                data: data,
                beforeSend: function (request) {
                    request.setRequestHeader("identity_type", data.loginType)
                    request.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*!/!*;q=0.8,application/signed-exchange;v=b3;q=0.9")
                    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
                },
                success: function (data) {
                    /!*{
                    "readyState":4,
                    "responseText":"{\"code\":500,\"message\":\"dd\",\"data\":null}",
                    "responseJSON":{"code":500,"message":"","data":null},
                    "status":200,
                    "statusText":"success"
                    }*!/
                    if(data.status === 200
                        && data.responseJSON && data.responseJSON.code !== 200) {
                        alert(data.responseJSON.message);
                    } else {
                        alert(data.message);
                    }
                },
                complete: function (data) {
                },
                error: function (err) {
                    alert(JSON.stringify(err));
                }
            });
        });
    })();*/
</script>
</html>
